﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using EluZSProvider;
using Antu.Core.Services;
using System.Data;

namespace WebSys.UI.Control.ZhengShou.OfficeFlow
{
    public class CaiQianKunNanHu:Page
    {
        protected global::System.Web.UI.WebControls.TextBox txtID;
        protected global::System.Web.UI.WebControls.Panel panel1;
        protected global::System.Web.UI.WebControls.Button Refresh;
        protected global::Antu.WebControls.MPPersistence PersistenceControl1;
        protected global::Antu.WebControls.CustomGridView GridView1;
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (!Page.IsPostBack)
            {
                string id=Request["id"];
                PersistenceControl1.Table = "AT_CQHBUY";
                PersistenceControl1.Key = "ID";
                PersistenceControl1.KeyValue = id;
                PersistenceControl1.ConnStr = _EluZSDataProvider.GetConnectionString();//数据库链接字符串
               
                if(string.IsNullOrEmpty(txtID.Text.Trim())){
                    txtID.Text = System.Guid.NewGuid().ToString().Replace("-", "").ToUpper();
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>nonetr1();</script>");
                }
                else
                {
                    BindData();
                }
            }
            PersistenceControl1.BindControl = panel1;
            Refresh.Click += new EventHandler(Refresh_Click);
        }

        #region 刷新家庭人员信息
        /// <summary>
        /// 刷新家庭人员信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void Refresh_Click(object sender, EventArgs e)
        {
            BindData();
            UpHz();
        }
        #endregion

        #region 返回户主号
        /// <summary>
        /// 返回户主号
        /// </summary>
        /// <returns></returns>
        public string GetHZID()
        {
            string hzid = "";
            if (!string.IsNullOrEmpty(txtID.Text.Trim()))
            {
                string sql = "select id from zs_family where id=hzid and sid='"+txtID.Text.Trim()+"' and tablename='' and 申请类型='浦口区被拆迁住房困难户购买经济适用住房'";
                hzid = _EluZSDataProvider.GetString(sql);
                if (string.IsNullOrEmpty(hzid))
                {
                    hzid = System.Guid.NewGuid().ToString().Replace("-", "").ToUpper();
                }
            }
            else
            {
                hzid = System.Guid.NewGuid().ToString().Replace("-", "").ToUpper();
            }
            return hzid;
        }
        #endregion

        #region  绑定家庭成员
        /// <summary>
        /// 绑定家庭成员
        /// </summary>
        public void BindData()
        {
            string sql = "select count(*) from ZS_FAMILY where  申请类型='浦口区被拆迁住房困难户购买经济适用住房 ' and sid='" + txtID.Text.Trim() + "' ";
            DataTable dt = _EluZSDataProvider.GetTable(sql);
            if (dt.Rows.Count>0)
            {
                GridView1.DataSource = dt;
                GridView1.DataBind();
            }
            else
            {
                GridView1.Visible = false;
            }
        }
        #endregion

        #region 更新户主信息
        /// <summary>
        /// 更新户主信息
        /// </summary>
        public void UpHz()
        {
            
        }
        #endregion
    }
}
